
(function($){
	$.fn.gdocsViewer = function(options) {
		var settings = {
			width  : '100%',
			height : '700'
		};
		
		if (options) { 
			$.extend(settings, options);
		}
		
		return this.each(function() {
			var file = $(this).attr('contextmenu');
			console.log(file);
            // int SCHEMA = 2, DOMAIN = 3, PORT = 5, PATH = 6, FILE = 8, QUERYSTRING = 9, HASH = 12
			var extregex = /^((http[s]?|ftp):\/)?\/?([^:\/\s]+)(:([^\/]*))?((\/[\w/-]+)*\/)([\w\-\.]+[^#?\s]+)(\?([^#]*))?(#(.*))?$/i;
			var ext = file.match(extregex)[8].split(".").pop();
            console.log("Extension : "+ext);
			if (/^(tiff|pdf|ppt|pptx|pps|doc|docx|txt|xls|xlsx)$/.test(ext)) {
				//var element = $(this).closest('.pswp__container').find('.pswp__item:first').clone(true);
				$('.modal-content').html('');
				$('.modal-content').append(function () {
					var id = $(this).attr('id');
					var gdvId = (typeof id !== 'undefined' && id !== false) ? id + '-gdocsviewer' : '';
					return  '<div id="' + gdvId + '" class="gdocsviewer customeviewer" ><iframe frameborder="0" src="http://docs.google.com/viewer?embedded=true&url=' + file + '" width="' + settings.width + '" height="' + settings.height + '" style="border: none;margin : 0 auto; display : block;"></iframe></div>';
				})
			}
		});
	};
})( jQuery );



//openPhotoSwipe();

